//
//  ViewController.m
//  03-UIGestureRecognizer
//
//  Created by 韩旭 on 16/7/18.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIView *viewHand;
@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //  手势识别器  UIGestureRecognizer
//    UIGestureRecognizer 作为所有手势的基类（父类）
    //    分为七种
    //   1. 轻拍
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    //    点击几次触发
    tap.numberOfTapsRequired = 1;
    //    几个手指触发(按option - alt) 默认是一个
    tap.numberOfTouchesRequired = 1;
    [self.view addGestureRecognizer:tap];
    
    //   2. 长按
    UILongPressGestureRecognizer *longtouch = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
//    长按几秒后开始, 默认是0.5s
    longtouch.minimumPressDuration = 1;
//    默认是10像素，长按失败前, 最大的移动距离
    longtouch.allowableMovement = 10;
    [self.view addGestureRecognizer:longtouch];
    //   3. 清扫
//    
    UISwipeGestureRecognizer *swith = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swithWithBtn:)];
//      direction 可以设置多个, 前提多个方向触发的行为相同
//    如果多个枚举方向触发的行为不同, 需要创建多个清扫的手势
//  左右 与 上下有冲突
//  练习：ImageView添加清扫换图
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 355, 647)];
    self.imageView.backgroundColor = [UIColor cyanColor];
    self.imageView.image = [UIImage imageNamed:@"020035625"];
    self.imageView.userInteractionEnabled = YES;
    [self.view addSubview:_imageView];
    swith.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp;
    [_imageView addGestureRecognizer:swith];
//    按位枚举, 4个选项 -> 1 1 1 1
//    全选的情况 1（4）1（3）1（2）1（1）1（0）
    
    
    
    
//    swith.direction = UISwipeGestureRecognizerDirectionRight;
//    [_imageView addGestureRecognizer:swith];
    
    
//     UISwipeGestureRecognizer *swith1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swithWithBtnS:)];
//    swith.direction = UISwipeGestureRecognizerDirectionLeft;
//    [_imageView addGestureRecognizer:swith1];

//       4 平移 pan
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(PanAction:)];
    [self.imageView addGestureRecognizer:pan];
    //   捏合pich
    UIPinchGestureRecognizer *pon = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchArr:)];
    [self.imageView addGestureRecognizer:pon];
    
//     5   旋转Rot
    UIRotationGestureRecognizer *rottion = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rottion:)];
    [self.imageView addGestureRecognizer:rottion];
    
//       6 屏幕边缘手势
    UIScreenEdgePanGestureRecognizer *screen =[[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screen:)];
    [self.view addGestureRecognizer:screen];
    
}
//轻拍的方法
- (void)tapAction:(UITapGestureRecognizer *)tap {
    NSLog(@"轻拍");
}
//长按手势方法
- (void)longPressAction:(UILongPressGestureRecognizer *)tap {
    if (tap.state == UIGestureRecognizerStateBegan) {
        NSLog(@"长按开始");
    } else if (tap.state == UIGestureRecognizerStateEnded) {
        NSLog(@"长按结束");
    }
}
- (void)swithWithBtn:(UISwipeGestureRecognizer *)swith {
    
//    UIImageView *unge = (UIImageView *)swith.view;
    NSLog(@"%ld", swith.direction);
       if (swith.direction & UISwipeGestureRecognizerDirectionRight) {
           
           
           NSLog(@"%ld", swith.direction);
//    unge.image = [UIImage imageNamed:@"01N8HEIAR80X"];
//           self.imageView = unge;
//       } else {
//    unge.image = [UIImage imageNamed:@"20150329_225211_791"];
//        self.imageView = unge;
       }

    
    
}
- (void)swithWithBtnS:(UISwipeGestureRecognizer *)swith {

   
}
- (void)PanAction:(UIPanGestureRecognizer *)pan{
//    NSLog(@"平移");
    if (pan.state == UIGestureRecognizerStateChanged) {
//        平移开始
    }else if (pan.state == UIGestureRecognizerStateChanged){
        //    平移手势,根据View上移动的过程,得到最终点
        CGPoint point = [pan translationInView:pan.view];
        
        //    根据point pan.view移动
        pan.view.transform =CGAffineTransformTranslate(pan.view.transform, point.x, point.y);
        //    pan 移动置空
        [pan setTranslation:point inView:pan.view];

    }else if (pan.state == UIGestureRecognizerStateChanged){
//        平移结束
        pan.view.transform = CGAffineTransformIdentity;
    }
}
- (void)pinchArr:(UIPinchGestureRecognizer *)pinch {
    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
    pinch.scale = 1;
    
}

- (void)rottion:(UIRotationGestureRecognizer *)rottion {
//    转换中,根据上次换继续改变
    rottion.view.transform = CGAffineTransformRotate(rottion.view.transform, rottion.rotation);
//    旋转弧度记为0;
    rottion.rotation = 0;
    
}

- (void)screen:(UIScreenEdgePanGestureRecognizer *)screen{
    NSLog(@"FWfwf");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
